import request from '../utils/request';
import config from "../../config/config";

// 获取项目列表
export const projectList = (params) => {
  console.log(params)
  return request.post(config.baseURL + "zsProject/index", params);
};

// 新增项目
export const projectAdd = (params) => {
  return request.post(config.baseURL + "zsProject", params);
};

// 修改项目
export const projectEdit = (params) => {
  return request.post(config.baseURL + "zsProject/update", params);
};

// 修改项目
export const projectDelete = (serialize) => {
  return request.delete(config.baseURL + "zsProject/" + serialize);
};


// 获取问卷列表
export const surveyList = (params) => {
  console.log(params)
  return request.post(config.baseURL + "zsSurvey/index", params);
};

// 获取问卷详情
export const surveydetail = (id) => {
  return request.get(config.baseURL + "zsSurvey/get?id=" + id);
};

// 新增问卷
export const surveyAdd = (params) => {
  return request.post(config.baseURL + "zsSurvey", params);
};

// 修改问卷
export const surveyEdit = (params) => {
  return request.post(config.baseURL + "zsSurvey/update", params);
};

// 删除问卷
export const surveyDelete = (serialize) => {
  return request.delete(config.baseURL + "zsSurvey/" + serialize);
};

// 保存设计结果
export const surveyDesignSave = (params) => {
  return request.post(config.baseURL + "zsSurvey/design", params);
};

// 获取设计结果
export const surveyDesign = (params) => {
  return request.get(config.baseURL + "zsSurvey/design?id=" + params.id);
};


// 获取外线号码列表
export const pstnList = (params) => {
  console.log(params)
  return request.post(config.baseURL + "zsPstn/index", params);
};

export const pstnSync = (params) => {
  return request.post(config.baseURL + "zsPstn/sync", params);
};

// 新增外线号码列表
export const pstnAdd = (params) => {
  return request.post(config.baseURL + "zsPstn", params);
};

// 分配热线号码
export const pstnAllocation = (params) => {
  return request.post(config.baseURL + "zsPstn/allocation", params);
};

// 修改外线号码列表
export const pstnEdit = (params) => {
  return request.post(config.baseURL + "zsPstn/update", params);
};

// 删除外线号码列表
export const pstnDelete = (serialize) => {
  return request.delete(config.baseURL + "zsPstn/" + serialize);
};

// 外线号码授权
export const pstnAuth = (params) => {
  return request.post(config.baseURL + "zsPstn/auth", params);
};

// 班次查询
export const shiftList = (params) => {
  return request.post(config.baseURL + "zsWorkShift/index", params);
};

// 班次新增
export const shiftSave = (params) => {
  return request.post(config.baseURL + "zsWorkShift", params);
};

// 班次删除
export const shiftDelete = (serialize) => {
  return request.delete(config.baseURL + "zsWorkShift/" + serialize);
};

// 班次报名保存
export const recordSave = (serialize) => {
  return request.post(config.baseURL + "zsWorkRecord", serialize);
};

// 班次报名记录列表
export const recordList = (serialize) => {
  return request.post(config.baseURL + "zsWorkRecord/index", serialize);
};

// 班次报名记录修改
export const recordUpdate = (serialize) => {
  return request.post(config.baseURL + "zsWorkRecord/update", serialize);
};

// 验证我能参加某一个问卷的调查
export const canIStart = (serialize) => {
  return request.get(config.baseURL + "zsWorkRecord/valid/" + serialize);
};

// 下载问卷号码库导入模板
export const downloadTemplate = (serialize) => {
  return request.get(config.baseURL + "zsSurvey/template/" + serialize, {responseType: 'blob'});
};

// 同步队列信息
export const syncQueueInfo = (params) => {
  return request.post(config.baseURL + "zsQueue/sync", JSON.stringify({queueNames: params}));
};

// 本地所有队列
export const queueAll = (params) => {
  return request.post(config.baseURL + "zsQueue/all", {});
};

// 坐席新增
export const seatAdd = (params) => {
  return request.post(config.baseURL + "zsSeat", params);
};

// 修改坐席
export const seatEdit = (params) => {
  return request.post(config.baseURL + "zsSeat/update", params);
};

// 坐席查询
export const seatList = (params) => {
  return request.post(config.baseURL + "zsSeat/index", params);
};

// 同步队列下的坐席
export const seatSync = (params) => {
  return request.post(config.baseURL + "zsSeat/sync", params);
};

// 同步所有
export const seatSyncAll = () => {
  return request.post(config.baseURL + "zsSeat/syncAll", {});
};

// 队列查询
export const queueList = (params) => {
  return request.post(config.baseURL + "zsQueue/index", params);
};

export const queueSync = (params) => {
  return request.post(config.baseURL + "zsQueue/syncQueue", params);
};

// 坐席删除
export const seatDelete = (serialize) => {
  return request.delete(config.baseURL + "zsSeat/" + serialize);
};

// 我参与过的问卷
export const myShifts = (params) => {
  return request.post(config.baseURL + "zsWorkRecord/me", params);
};

export const myAnswers = (params) => {
  // return request.post()
};

// 被呼客户信息查询
export const infoList = (params) => {
  return request.post(config.baseURL + "zsInfo/index", params);
};

// 被呼客户信息删除
export const infoDelete = (serialize) => {
  return request.delete(config.baseURL + "zsInfo/" + serialize);
};

// 号码授权信息查询
export const numberCompanyList = (params) => {
  return request.post(config.baseURL + "zsNumberCompany/index", params);
};


// 号码授权信息删除
export const numberCompanyDelete = (serialize) => {
  return request.delete(config.baseURL + "zsNumberCompany/" + serialize);
};

// 问题列表
export const questionList = (params) => {
  return request.post(config.baseURL + "zsQuestion/list", params);
};

// 数据源查询
export const datasourceList = (params) => {
  return request.post(config.baseURL + "datasource/index", params);
};

// 数据源查询
export const datasourceAdd = (params) => {
  return request.post(config.baseURL + "datasource", params);
};

// 问卷提交
export const submitAnswers = (params, uuid, phone, surveyId) => {
  let parse = JSON.parse(JSON.stringify(params));
  console.log(parse)
  for (let i = 0; i < parse.length; i++) {
    let parseElement = parse[i];
    delete parse[i]["children"];
    let a = parseElement['answers'];
    console.log(a);
    if (!(a instanceof Array)) {
      let answers = [];
      answers.push(a);
      parse[i].answers = answers;
    }
  }
  let paramsForPost = {"questions": parse, "surveyId": surveyId};
  return request.post(config.baseURL + "zsAnswer/submit/" + phone + "/" + uuid, paramsForPost);
};


export const answerList = (params) => {
  return request.post(config.baseURL + "zsAnswer/index", params);
};

/**
 * 查询模式
 * @param params
 * @returns {AxiosPromise<any>}
 */
export const dbSchamaList = (option, params) => {
  return request.post(config.baseURL + "datasource/model/" + option.id, params);
};

/**
 * 查询表
 * @param params
 * @returns {AxiosPromise<any>}
 */
export const dbTableList = (option, params) => {
  return request.post(config.baseURL + "datasource/table/" + option.id + "/" + option.schama, params);
};

// 数据源查询
export const columnList = (params) => {
  return request.post(config.baseURL + "datasource/column", params);
};

// 数据源查询
export const columnsSave = (params) => {
  return request.post(config.baseURL + "tbColumn/save", params);
};

export const apiAdd = (params) => {
  return request.post(config.baseURL + "tbApi", params);
}

export const apiEdit = (params) => {
  return request.post(config.baseURL + "tbApi/update", params);
}

export const apiList = (params) => {
  return request.post(config.baseURL + "tbApi/index", params);
}

export const dictList = (params) => {
  return request.post(config.baseURL + "tbDict/index", params);
}

export const dictAdd = (params) => {
  return request.post(config.baseURL + "tbDict", params);
}

export const dictDel = (serialize) => {
  return request.delete(config.baseURL + "tbDict/" + serialize);
}

export const dictEdit = (params) => {
  return request.post(config.baseURL + "tbDict/update", params);
}

export const dictValueAdd = (params) => {
  return request.post(config.baseURL + "tbDictValue", params);
}

export const dictValueEdit = (params) => {
  return request.post(config.baseURL + "tbDictValue/update", params);
}

export const dictValueDel = (serialize) => {
  return request.delete(config.baseURL + "tbDictValue/" + serialize);
}

export const dictValueList = (params) => {
  return request.post(config.baseURL + "tbDictValue/index", params);
}

// 获取样本答题详情
export const answerDetail = (id) => {
  return request.get(config.baseURL + "zsAnswer/get?id=" + id);
}

// 获取样本答题详情
export const answerOptionDetail = (id) => {
  return request.get(config.baseURL + "zsAnswer/options/detail?id=" + id);
}

// 审核通过
export const checkPass = (id, reviewSpent) => {
  return request.put(config.baseURL + "zsAnswer/pass", {id: id, reviewSpent: reviewSpent});
}

// 审核作废
export const checkCancel = (id, reviewMsg, reviewSpent) => {
  return request.put(config.baseURL + "zsAnswer/cancel", {id: id, reviewMsg: reviewMsg, reviewSpent: reviewSpent} );
}

// 微信公众号账户新增
export const wxAccountAdd = (params) => {
  return request.post(config.weixinURL + "wxAccount", params);
}

export const wxAccountList = (params) => {
  return request.post(config.weixinURL + "wxAccount/index", params);
}

export const wxAccountDel = (serialize) => {
  return request.delete(config.weixinURL + "wxAccount/" + serialize);
}

export const wxAccountEdit = (params) => {
  return request.post(config.weixinURL + "wxAccount/update", params);
}

export const wxRefreshToken = (serialize) => {
  return request.post(config.weixinURL + "wxAccount/refreshToken/" + serialize);
}

export const wxAccountAll = () => {
  return request.post(config.weixinURL + "wxAccount/all", {});
}

export const wxMenuSave = (params) => {
  return request.post(config.weixinURL + "wxMenu", params);
}

export const wxMenus = (wxAccountId) => {
  return request.post(config.weixinURL + "wxMenu/menus", {wxAccountId: wxAccountId});
}

export const wxMenuDeploy = (wxAccountId) => {
  return request.post(config.weixinURL + "wxMenu/deploy", {wxAccountId: wxAccountId})
}




